*****************************************************************************************
* Estimate Relative Demand Specifications 
****************************************************************************************

set more off
clear

eststo clear

log using "$log_files/5_demand_estimation", replace name(mainlog)

*Define global specification variables: 

*run time vs goods estimation if 1
global est_time_goods=1

*run chcare vs goods estimation if 1
global est_chcare_goods=1



******************************************************************
**   A. Download child panel with reasonably aged parents*********
******************************************************************

clear 
use "$data/psid_fam.dta", replace


******************************************************************
***********    B. Sample restrictions ***************
******************************************************************

* restrict to those with some measure of investment in CDS_invest_ind
keep if CDS_invest_ind==1

***********    Keep kids ages 5-12 only    ***************

keep if age>=5 & age<=12

************ Families with only 1 or 2 children ages<=12 ************

keep if num_0_12<=2

*************** Only include CDS years 1997, 2002, 2007 ****************

* keep if year==1997 | year==2002 | year==2007

****** ONLY KEEP LOG WAGE FE VALUES IF AT LEAST 3 OBSERVATIONS USED *******

local N_min_FE = 5     // Minimum number of observed wages to keep log wage FE

replace ln_wageFE_m  =. if N_FE_m< `N_min_FE' 
replace ln_wageFE_f  =. if N_FE_f< `N_min_FE'  


*******************************************************************************************************
*************************************   C. LOCAL LISTS OF REGRESSORS  *********************************
*******************************************************************************************************

local medvars    "med_hs med_scoll med_collplus"
local fedvars    "fed_hs fed_scoll fed_collplus"
local fvars      "fed_hs fed_scoll fed_collplus f_age"
local famvars    "m_white num_0_5 num_child"


local p_work_min_m= .75               // to limit sample to those with a minimum probability of mother working
local p_work_min_f= .90               // to limit sample to those with a minimum probability of father working


local Zm1 = " "
local Zm2 = " `medvars' "
local Zm3 = " age `medvars' m_age"
local Zm4 = " age `medvars' m_age `famvars' "
local Zm5 = " age med_scoll med_collplus m_age `famvars' "
local Zm6 = " age med_scoll med_collplus m_age `famvars' m_pc97 "

local Zf1 = " "
local Zf2 = " `fedvars' "
local Zf3 = " age `fedvars' f_age"
local Zf4 = " age `fedvars' f_age `famvars' "
local Zf5 = " age fed_scoll fed_collplus f_age `famvars' "
local Zf6 = " age fed_scoll fed_collplus f_age `famvars' "

local Z1  = " "
local Z2  = " `medvars' `fedvars' "
local Z3  = " age `medvars' m_age `fedvars' f_age "
local Z4  = " age `medvars' m_age `fedvars' f_age `famvars' "
local Z5  = " age med_scoll med_collplus m_age fed_scoll fed_collplus f_age `famvars' "
local Z6  = " age med_scoll med_collplus m_age fed_scoll fed_collplus f_age `famvars' m_pc97 "


local Zm0 = " age ln_wageFE_m `famvars' "
local Zf0 = " age ln_wageFE_f `famvars' "
local Z0  = " age ln_wageFE_m ln_wageFE_f `famvars'"

local Zm7 = " age ln_wageFE_m `famvars' "
local Zf7 = " age ln_wageFE_f `famvars' "
local Z7  = " age ln_wageFE_m ln_wageFE_f `famvars'"




local Zall2  = " curr_married `medvars' `fedvars' "
local Zall3  = " curr_married age `medvars' m_age fed_all_hs fed_all_scoll fed_all_collplus f_all_age "
local Zall4  = " curr_married age `medvars' m_age fed_all_hs fed_all_scoll fed_all_collplus f_all_age `famvars' "
local Zall5  = " curr_married age med_scoll med_collplus m_age fed_all_scoll fed_all_collplus f_all_age `famvars' "
local Zall6  = " curr_married age med_scoll med_collplus m_age fed_all_scoll fed_all_collplus f_all_age `famvars' m_pc97 "


gen m_pw_inst = m_pred_lnwage_mean_occ_state // Set main predicted wage instrumental variables for mothers
gen f_pw_inst = f_pred_lnwage_mean_occ_state // Set main predicted wage instrumental variables for fathers

* Select staff ratio variable to include in specs
*gen SR = staff_ratio     
gen SR = staff_ratio_6m
	

* Generate an alternative father's education variable equal to zero (instead of missing) if unmarried
gen fed_all_hs = fed_hs
gen fed_all_scoll = fed_scollplus
gen fed_all_collplus = fed_collplus
gen f_all_age = f_age

replace fed_all_hs = 0 if curr_married==0
replace fed_all_scoll = 0 if curr_married==0
replace fed_all_collplus = 0 if curr_married==0
replace f_all_age = 0 if curr_married==0

gen m_age_sq = m_age*m_age
gen f_age_sq = f_age*f_age



**************************************************************************************
********* D. PRELIMINARY ANALYSIS AND SUMMARY STATISTICS  ****************************
**************************************************************************************


*************************************   PREDICTED WORK PROBABILITIES  ******************************
* Probabilities of positive hours observation (i.e. predicted probability of 'working') -- separately for married & single mothers

*Single mothers
probit pos_hrs_m  `medvars' m_age `famvars' age_youngest i.age i.year   if curr_married==0
predict prob_work_m0 if e(sample)
eststo margin: margins, dydx(*) post
estimates store est_work_m0

*Married mothers
probit pos_hrs_m  `medvars' m_age `famvars' age_youngest `fedvars' f_age  i.age i.year  if curr_married==1
predict prob_work_m1 if e(sample)
eststo margin: margins, dydx(*) post
estimates store est_work_m1

*All mothers
gen prob_work_m = prob_work_m0
replace prob_work_m = prob_work_m1 if curr_married==1

*Fathers
probit pos_hrs_f  `medvars' m_age `famvars' age_youngest `fedvars' f_age  i.age i.year  if curr_married==1
predict prob_work_f if e(sample)
eststo margin: margins, dydx(*) post
estimates store est_work_f



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-2: Predicted probability (average derivatives) of work probits for parents
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab  est_work_m0 est_work_m1 est_work_f using "$tables/prob_work.tex",  coeflab(curr_married "Married"  age "Child's age" age_youngest "Age of youngest child" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age"  fed_hs "Father HS grad"  fed_scoll "Father some coll."  fed_collplus "Father coll+" f_age "Father's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children") stats(N, fmt(0))  ti(Appendix Table: Predicted probability (average derivatives) of work probits for parents (1-2 kids ages 0-12)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(30) modelwidth(10) wrap style(tex)  mtitles("Single Mothers" "Married Mothers"  "Married Fathers" )  replace



sort kid year
save  "$temp/allfam_tmp.dta", replace                        // save data


*************************************  LOG WAGE REGRESSIONS  ******************************
* restricting to high work probabilities



regress ln_wage_m med_scoll med_collplus m_age m_age_sq m_white    if (curr_married==0 & prob_work_m >= `p_work_min_m' & prob_work_m !=.)
estimates store est_wage_m0

regress ln_wage_m med_scoll med_collplus m_age m_age_sq m_white    if (curr_married==1 & prob_work_m >= `p_work_min_m' & prob_work_m !=.)
estimates store est_wage_m1

regress ln_wage_f `fedvars' f_age f_age_sq m_white                 if (curr_married==1 & prob_work_f >= `p_work_min_f' & prob_work_f !=.)
estimates store est_wage_f


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-3: Log wage regressions for parents
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab  est_wage_m0 est_wage_m1 est_wage_f using "$tables/wage_regs_pwork.tex", rename(f* m*) coeflab(curr_married "Married"  age "Child's age" med_hs "Parent HS grad"  med_scoll "Parent some coll."  med_collplus "Parent coll+"  m_age "Parent's age"  m_age_sq "Parent's age squared" fed_hs "Parent HS grad"  fed_scoll "Parent some coll."  fed_collplus "Parent coll+"  f_age "Parent's age"  f_age_sq "Parent's age squared" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children") stats(r2 N, fmt(3 0))  ti(Appendix Table: Log wage regressions for parents (1-2 kids ages 0-12, P(work) $ \geq $ `p_work_min_m' or `p_work_min_f')) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(30) modelwidth(15) wrap style(tex)  mtitles( "Single Mothers" "Married Mothers"  "Married Fathers")  replace




************************* PREDICTED POSITIVE CHILDCARE EXPENDITURES ***************************************

* Look at whether positive childcare expenditures is related to family characteristics & prices

local pccare = "pos_chcare_imp"   

keep if year==2002 | year==2007


* no restrictions on probability of work

foreach pvar in 4ca{

    disp  _n(1) "Price measure: `pvar'" _n(1)	

	disp _n(2) "Probability of positive child care expenditures"
	probit `pccare'   ln_pratio_`pvar' `Zm5' curr_married i.year  ind_same_state old_child
		eststo margin: margins, dydx(*) post
	estimates store est_all5
	

	

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-13: Probit estimates for positive child care expenditures
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab  est_all5  using "$tables/pos_childcare_`pvar'.tex", coeflab(curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age"  fed_hs "Father HS grad"  fed_scoll "Father some coll."  fed_collplus "Father coll+" f_age "Father's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children" ind_same_state "HH Head same state" old_child "Any children ages 13+" old_child_2plus "2+ children ages 13+") stats(N, fmt(0))  ti(Appendix Table: Probit estimates for positive child care expenditures (1-2 kids ages 0-12, `pccare', 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(30) modelwidth(10) wrap style(tex) mtitles("All Mothers" "All Mothers")   replace

}


************************* SUMMARY STATS 2002 & 2007 FOR FULL VS. RESTRICTED SAMPLES ***************************************


generate year2007=(year==2007)
replace year2007=. if year==.



disp "Summary statistics for full sample: 2002 and 2007"
eststo t_all: estpost summ ln_wage_m_rel ln_wage_f_rel ln_pratio_4ca age `medvars' m_age `fedvars' f_age `famvars' year2007

disp "Summary statistics for sample with high predicted probability of work for mothers: 2002 and 2007"	
eststo t_rest_prob: estpost summ ln_wage_m_rel ln_wage_f_rel ln_pratio_4ca age `medvars' m_age `fedvars' f_age `famvars' year2007  if prob_work_m >= `p_work_min_m' & prob_work_m !=.

disp "Summary statistics for sample with positive childcare expenditures: 2002 and 2007"	
eststo t_rest_chcare: estpost summ ln_wage_m_rel ln_wage_f_rel ln_pratio_4ca age `medvars' m_age `fedvars' f_age `famvars' year2007 if `pccare'==1

*  Sample used in table 2
preserve
keep if prob_work_m >= `p_work_min_m' & prob_work_m !=.
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm4'
disp "Summary statistics for sample used in table 2"	
eststo t_rest_table2: estpost summ ln_wage_m_rel ln_wage_f_rel ln_pratio_4ca age `medvars' m_age `fedvars' f_age `famvars' year2007 if e(sample)==1

* Sample used in table 4
restore
foreach pvar in 4ca {
local zval= 5 
		regress ln_invratio_imp  ln_pratio_`pvar' `Zall`zval''
}
disp "Summary statistics for sample used in table 4"	
eststo t_rest_table4: estpost summ ln_wage_m_rel ln_wage_f_rel ln_pratio_4ca age `medvars' m_age `fedvars' f_age `famvars' year2007  if e(sample)==1


*************************Residual Variances for MC analysis*****************************************

preserve
* Use sample corresponding to Table 2 Column 2
keep if prob_work_m >= `p_work_min_m' & prob_work_m !=.
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5'
generate sample_dummy=1 if e(sample)==1
replace sample_dummy=0 if sample_dummy==.
* Var(zeta)
display e(rss)/(e(N)-1)

* Var(ln(pi))
regress ln_wage_m_rel curr_married `Zm5' if sample_dummy==1
display e(rss)/(e(N)-1)

* Var(ln(x_1))
generate ln_g=ln_hhinvest-ln(p_avg)
regress ln_g curr_married `Zm5' if sample_dummy==1
predict res_g, residuals
replace res_g=. if sample_dummy==0
display e(rss)/(e(N)-1)

* Correlations of residuals
regress ln_tau_m curr_married `Zm5' if sample_dummy==1
predict res_tau_m, residuals
replace res_tau_m=. if sample_dummy==0

regress ln_tau_f curr_married `Zm5' if sample_dummy==1
predict res_tau_f, residuals
replace res_tau_f=. if sample_dummy==0

generate ln_chcare_imp1=ln_chcare_imp-ln_pchcare_4ca
regress ln_chcare_imp1 curr_married `Zm5' if sample_dummy==1
predict res_chcare, residuals
replace res_chcare=. if sample_dummy==0

correlate res_g res_tau_m
correlate res_g res_tau_m res_tau_f if curr_married==1
correlate res_g res_chcare res_tau_m res_tau_f if curr_married==1
correlate res_g res_tau_m if curr_married==0
correlate res_g res_chcare res_tau_m if curr_married==0

restore

**************************************************************************************************


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Table 1: Summary statistics for full sample: 2002 and 2007
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
`'
esttab  t_all using "$tables/all_summary.tex", booktabs  label nonumbers cells( "count(fmt(%2.0f) label(N)) mean(fmt(%8.2f) label(Mean)) sd(fmt(%8.2f) label(SD)) min(fmt(%8.2f) label(Min)) max(fmt(%8.2f) label(Max))")  ti(Summary statistics for full sample: 2002 and 2007) noobs  varwidth(15) modelwidth(11) wrap style(tex)  replace /*
*/  varlabels( ln_pratio_4ca "$\ln(\tilde{P}_{c,i})$" year2007 "Year 2007"   ln_wage_f_rel "$\ln(\tilde{W}_{f})$"  ln_wage_m_rel "$\ln(\tilde{W}_{m})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll." med_scollplus "Mother some coll. + "  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children"  fed_hs "Father HS grad"  fed_scoll "Father some coll." fed_scollplus "Father some coll. + "  fed_collplus "Father coll+"  f_age "Father's age") 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-1: Summary statistics for restricted samples: 2002 and 2007
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab t_rest_prob t_rest_table2 t_rest_chcare t_rest_table4 using "$tables/all_restricted_summary.tex", booktabs  label  mtitle("High predicted probability of work for mothers" "Table 2 baseline" "Positive childcare expenditures"  "Table 4 baseline") cells( "count(fmt(%2.0f) label(N)) mean(fmt(%8.2f) label(Mean)) sd(fmt(%8.2f) label(SD))") ti(Summary statistics for restricted samples: 2002 and 2007) noobs  varwidth(15) modelwidth(11) wrap style(tex)  replace varlabels( ln_pratio_4ca "$\ln(\tilde{P}_{c,i})$"   year2007 "Year 2007"  ln_wage_f_rel "$\ln(\tilde{W}_{f})$"  ln_wage_m_rel "$\ln(\tilde{W}_{m})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll." med_scollplus "Mother some coll. + "  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children" fed_hs "Father HS grad"  fed_scoll "Father some coll." fed_scollplus "Father some coll. + "  fed_collplus "Father coll+"  f_age "Father's age")






//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix  Figure G-6: Distributions of log relative input prices (PSID, 2002 and 2007)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* Distribution of relative prices

quietly kdensity ln_wage_m_rel 

local bdw_m: display %4.3f r(bwidth) 

quietly kdensity ln_wage_f_rel 
local bdw_f: display %4.3f r(bwidth) 
local krn=r(kernel) 

twoway (kdensity ln_wage_m_rel) (kdensity ln_wage_f_rel), legend(label(1 "Mother ") label(2 "Father")  region(lcolor(white))) ytitle("") /* title("Density plot: relative wages",  size(medlarge)) subtitle("( kernel: `krn'; bandwidth: mothers `bdw_m', fathers `bdw_f' )", size(medium)) */ xtitle("Relative wage") plotregion(fcolor(white)) bgcolor(white)  graphregion(fcolor(white) ilcolor(white) lcolor(white)) ylabel(, format(%03.2f) angle(horizontal))
	graph export "$graph/relative_wages.pdf", as(pdf) replace



quietly kdensity ln_pratio_4ca
local bdw_c: display %4.3f r(bwidth) 
local krn_c=r(kernel) 
	
twoway (kdensity ln_pratio_4ca) , /* title("Density plot: relative childcare price",  size(medlarge)) subtitle("( kernel: `krn_c'; bandwidth: `bdw_c' )",  size(medium)) */  xtitle("") ytitle("") plotregion(fcolor(white)) bgcolor(white)  graphregion(fcolor(white) ilcolor(white) lcolor(white)) ylabel(, format(%03.2f) angle(horizontal))
graph export "$graph/relative_chcare.pdf", as(pdf) replace

	


if $est_time_goods==1 {



****************************************************************************************************
******************** E. ESTIMATION: TIME RELATIVE TO HOUSEHOLD GOODS INPUTS (2002, 2007) ***********
****************************************************************************************************

clear 
use "$temp/allfam_tmp.dta"

************************** FULL SAMPLE (SINGLE MOTHERS AND TWO-PARENT HOUSEHOLDS)*************

keep if year==2002 | year==2007

* Probability of work restriction > 0.75
keep if prob_work_m >= `p_work_min_m' & prob_work_m !=.


*** Main estimates ***

* OLS estimates

forvalues zval=4/7 {
	disp _n(3) "OLS Specification " `zval' _n(2)
	regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm`zval''	
*	predict PHIm_ols`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhom_ols`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estm_ols`zval'
}

	
* IV estimates: state of residence

local zval= 5 
	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_m_g_exp_ratio curr_married `Zm`zval''  (ln_wage_m_rel=i.state i.year)
*	predict PHIm_ivs`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhom_ivs`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estm_ivs`zval'
	estat firststage
	estat endogenous
	local Hm`zval' = r(p)



* IV estimates: predicted wages

local zval= 5 
	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_m_g_exp_ratio curr_married `Zm`zval''  (ln_wage_m_rel=m_pw_inst)
*	predict PHIm_ivpw`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhom_ivpw`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estm_ivpw`zval'
	estat firststage
	estat endogenous
	local Hmpw`zval' = r(p)



***  Checking various predicted wage measures *** 

eststo clear 
local zval= 5 


	ivreg2 ln_tau_m_g_exp_ratio curr_married `Zm`zval''  (ln_wage_m_rel=m_pred_lnwage_mean_occ_state), first savefirst savefprefix(iv_all_pr1_`zval')
	estimates store est_all_iv_pr1_`zval'
	estadd scalar F_all_`zval' = `e(widstat)' : iv_all_pr1_`zval'*

	ivreg2 ln_tau_m_g_exp_ratio curr_married `Zm`zval''  (ln_wage_m_rel=m_pred_lnwage_mean_occ),  first savefirst savefprefix(iv_all_pr2_`zval')
	estimates store est_all_iv_pr2_`zval'
	estadd scalar F_all_`zval' = `e(widstat)' : iv_all_pr2_`zval'*

	
	ivreg2 ln_tau_m_g_exp_ratio curr_married `Zm`zval''  (ln_wage_m_rel=m_pred_lnwage_mean_state),  first savefirst savefprefix(iv_all_pr3_`zval')
	estimates store est_all_iv_pr3_`zval'
	estadd scalar F_all_`zval' = `e(widstat)' : iv_all_pr3_`zval'*

	
	ivreg2 ln_tau_m_g_exp_ratio curr_married `Zm`zval''  (ln_wage_m_rel=m_pred_lnwage), first savefirst savefprefix(iv_all_pr4_`zval')
	estimates store est_all_iv_pr4_`zval'
	estadd scalar F_all_`zval' = `e(widstat)' : iv_all_pr4_`zval'*





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Table 2: OLS and 2SLS estimates for mother time/goods relative demand
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab  estm_ols4 estm_ols5 estm_ols6 estm_ols7  estm_ivpw5  estm_ivs5 using "$tables/All_S1m.tex", coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$" curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children"  ln_wageFE_m "Mother's log wage FE" m_pc97 "Mother's cogn. score") stats(r2 N, fmt(3 0))  ti(OLS estimates for mother time/goods relative demand (ALL, 1-2 kids ages 0-12, P(work) $\geq$`p_work_min_m', 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(15) modelwidth(11) wrap style(tex) mtitles("OLS" "OLS" "OLS" "OLS" "IV (pred wage)" "IV (state, year)" )  replace



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-5: 2SLS estimates for mother time/goods relative demand using
*** different predicted wage measures as instruments
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

*** IV estimation with different predicted wage measures as instruments

esttab  est_all_iv_pr1_5 est_all_iv_pr2_5 est_all_iv_pr3_5 est_all_iv_pr4_5 using "$tables/All_S1m_IV_pred_5.tex",  coeflab(  ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children") stats(N, fmt(0))  ti(Appendix Table: IV estimates for mother time/goods relative demand using different predicted wage measures as instruments (ALL, 1-2 kids ages 0-12, P(work) $\geq$ `p_work_min_m', 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(15) modelwidth(10) wrap style(tex)  /*
*/ mtitles("Uses All Variation" "Excludes Avg. State Diff." "Excludes Avg. Occ Diff." "Excludes Avg. State and Occ Diff." )  replace


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-4: First-stage estimates for mother time/goods relative demand using 
*** different predicted wage measures as instruments
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

*First-stage of IV estimation with different predicted wage measures as instruments

esttab  iv_all_pr1_5* iv_all_pr2_5* iv_all_pr3_5* iv_all_pr4_5* using "$tables/All_S1m_IV_pred_5_first.tex", coeflab( m_pred_lnwage "Mother's predicted log wage" m_pred_lnwage_mean_state "Mother's predicted log wage" m_pred_lnwage_mean_occ "Mother's predicted log wage" m_pred_lnwage_mean_occ_state "Mother's predicted log wage" ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children") stats(F_all_5 N, fmt(3 0))  ti(Appendix Table: First-stage estimates for mother time/goods relative demand using different predicted wage measures as instruments (ALL, 1-2 kids ages 0-12, P(work) $\geq$ `p_work_min_m', 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(15) modelwidth(10) wrap style(tex)  /*
*/ mtitles("Uses All Variation" "Excludes Avg. State Diff." "Excludes Avg. Occ Diff." "Excludes Avg. State and Occ Diff." )  replace




****  Checking no and tighter restrictions on work probability for selected specifications of mothers ****

clear 
use "$temp/allfam_tmp.dta"
keep if year==2002 | year==2007

 * No restrictions on predicted probability of work
 
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5'	
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
local rhom_ols_no = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
capture noisily test med_scoll med_collplus
estimates store estm_ols_no

ivregress 2sls ln_tau_m_g_exp_ratio curr_married `Zm5'  (ln_wage_m_rel=m_pw_inst)
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
local rhom_ivs_no = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
capture noisily test med_scoll med_collplus
estimates store estm_ivs_no
hausman estm_ivs_no estm_ols_no, constant
local Hm_no = r(p)	

* Only those with very high predicted probability of work >0.85
keep if prob_work_m >= 0.85 & prob_work_m !=.



regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5'	
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
local rhom_ols_hi = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
capture noisily test med_scoll med_collplus
estimates store estm_ols_hi

ivregress 2sls ln_tau_m_g_exp_ratio curr_married `Zm5'  (ln_wage_m_rel=m_pw_inst)
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
local rhom_ivs_hi = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
capture noisily test med_scoll med_collplus
estimates store estm_ivs_hi
hausman estm_ivs_hi estm_ols_hi, constant
local Hm_hi = r(p)




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-6: OLS & 2SLS estimates for mother time/goods relative demand for different selection
***  on predicted probability of work
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab estm_ols5 estm_ols_no estm_ols_hi estm_ivs5 estm_ivs_no estm_ivs_hi using "$tables/All_S1m_OLSIV_Pwork.tex", coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children") stats(r2 N, fmt(3 0))  ti(Appendix Table: OLS \& IV (instruments: pred wage) estimates for mother time/goods relative demand for P(work) $ \geq $ `p_work_min_m', no restriction, and P(work) $ \geq $ 0.85 (ALL, 1-2 kids ages 0-12, 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(15) modelwidth(13) wrap style(tex) mtitles("Base (OLS)" "All (OLS)" "P(work)$\geq$0.85 (OLS)" "Base (IV)" "All (IV)" "P(work)$\geq$0.85 (IV)")  replace



****  Checking estimates for different kid ages  ****
 
clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
*Probability of work restriction > 0.75
keep if prob_work_m >= `p_work_min_m' & prob_work_m !=.


**All
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5'
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
estimates store estm_ols

local rssm_ols = e(rss)
local nm_ols=e(N) 
local k2m_ols=10

**Younger children
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5'	if age>=5 & age<=8
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
estimates store estm_ols_5_8
local rssm_ols_5_8 = e(rss)


**Older children
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5'	if age>=9 & age<=12
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
estimates store estm_ols_9_12
local rssm_ols_9_12 = e(rss)



*F-stat: test difference of coefficients (younger/older children)

local Fm_ols=(`nm_ols'-2*`k2m_ols')/`k2m_ols'*(`rssm_ols'-(`rssm_ols_5_8'+`rssm_ols_9_12'))/(`rssm_ols_5_8'+`rssm_ols_9_12')
local pm_ols=Ftail(`k2m_ols',`nm_ols'-2*`k2m_ols',`Fm_ols')
local p: display %4.3f `pm_ols'
estadd scalar p_val = `pm_ols' : estm_ols




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Apendix Table G-10: OLS estimates for mother time/goods relative demand by child age
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab  estm_ols estm_ols_5_8 estm_ols_9_12 using "$tables/All_S1m_OLS_age.tex", coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children") stats(r2 rss N , fmt(3 3 0))  ti(Appendix Table: OLS estimates for mother time/goods relative demand by child age (ALL, 1-2 kids ages 0-12, P(work) $ \geq $ `p_work_min_m' 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(15) modelwidth(13) wrap style(tex) mtitles("All" "Ages 5-8" "Ages 9-12") addnotes("p-value for (2) and (3)= `p'") replace



****  Checking whether achievement scores 1997 AP or LW  matter ****

 
clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
*Probability of work restriction > 0.75
keep if prob_work_m >= `p_work_min_m' & prob_work_m !=.
*Non-missing test scores restriction
keep if ap97!=. & lw97 !=.


*** All
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5'	
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
estimates store estm_ols_5
local rssm_ols_5 = e(rss)
local nm_ols_5=e(N) 
local k2m_ols_5=10

***Use average numeracy (AP)/literacy (LW) score
gen avgtest97=(ap97+lw97)/2

summ avgtest97, d
local med_avgtest97 = r(p50)

*Add test score as a control
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5' avgtest97	
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
estimates store estm_ols_avgtest97

*Restrict to high test score
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5' if avgtest97>`med_avgtest97' 
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
estimates store estm_ols_avgtest97pos
local rssm_ols_avgtest97pos = e(rss)

*Restrict to low  test score
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married `Zm5' if avgtest97<=`med_avgtest97' 	
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
estimates store estm_ols_avgtest97neg
local rssm_ols_avgtest97neg = e(rss)


*F-stat: test difference of coefficients (high/low average test score)

local Fm_ols_5=(`nm_ols_5'-2*`k2m_ols_5')/`k2m_ols_5'*(`rssm_ols_5'- (`rssm_ols_avgtest97pos' +`rssm_ols_avgtest97neg'))/(`rssm_ols_avgtest97pos' +`rssm_ols_avgtest97neg')
local pm_ols_5=Ftail(`k2m_ols_5',`nm_ols_5'-2*`k2m_ols_5',`Fm_ols_5')
local p: display %4.3f `pm_ols_5'
estadd scalar p_val= `pm_ols_5' : estm_ols_5



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-12: OLS estimates for mother time/goods relative demand conditioning on 1997 AP and LW scores
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab estm_ols_5 estm_ols_avgtest97 estm_ols_avgtest97neg estm_ols_avgtest97pos using "$tables/All_S1m_OLS_AP_LW.tex", coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children") stats(r2 rss N, fmt(3 3 0))  ti(Appendix Table: OLS estimates for mother time/goods relative demand conditioning on 1997 AP and LW scores (ALL, 1-2 kids ages 0-12, P(work) $ \geq $ `p_work_min_m' 2002 and 2007, p-value `pm_ols_5')) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(15) modelwidth(13) wrap style(tex) mtitles("Baseline" "Includes Avg Test 97" "Avg Test 97 low"  "Avg Test 97 high")  replace addnotes("p-value for (3) and (4) = `p'")




*************************** SINGLE MOTHERS (2002, 2007) **************************

clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
keep if curr_married==0
*Probability of work restriction > 0.75
keep if prob_work_m >= `p_work_min_m' & prob_work_m !=.



* OLS estimates

forvalues zval=1/7 {	
	disp _n(3) "OLS Specification " `zval' _n(2)
	regress ln_tau_m_g_exp_ratio  ln_wage_m_rel  `Zm`zval''	
	predict PHIms_ols`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhoms_ols`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estms_ols`zval'
}


* IV estimates: state of residence

forvalues zval=1/7 {
	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_m_g_exp_ratio `Zm`zval''  (ln_wage_m_rel=i.state i.year)
	predict PHIms_ivs`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhoms_ivs`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estms_ivs`zval'
	estat firststage
	hausman estms_ivs`zval' estms_ols`zval', constant
	local Hm`zval' = r(p)
}

* IV estimates: predicted wages

forvalues zval=1/7 {
	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_m_g_exp_ratio `Zm`zval''  (ln_wage_m_rel=m_pw_inst)
	predict PHImpw_ivpw`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhoms_ivpw`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estms_ivpw`zval'
	estat firststage
	hausman estms_ivpw`zval' estms_ols`zval', constant
	local Hmpw`zval' = r(p)
}

	
	

	
***************** TWO-PARENT HOUSEHOLDS (2002, 2007) ****************

clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
keep if curr_married==1
*Probability of work restriction > 0.75
keep if prob_work_m >= `p_work_min_m' & prob_work_m !=.


****************** Mother's time vs. goods **************************

* OLS estimates

forvalues zval=5/7 {
	disp _n(3) "OLS Specification " `zval' _n(2)
	regress ln_tau_m_g_exp_ratio  ln_wage_m_rel  `Zm`zval''	
	predict PHImm_ols`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhomm_ols`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily 
	estimates store estmm_ols`zval'
}
	
* IV estimates: state of residence

local zval= 5 
	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_m_g_exp_ratio `Zm`zval''  (ln_wage_m_rel=i.state i.year)
	predict PHImm_ivs`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhomm_ivs`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estmm_ivs`zval'
	estat firststage
	hausman estmm_ivs`zval' estmm_ols`zval', constant
	local Hm`zval' = r(p)



* IV estimates: predicted wages

local zval= 5 

	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_m_g_exp_ratio `Zm`zval''  (ln_wage_m_rel=m_pw_inst)
	predict PHImm_ivpw`zval'
	nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	capture noisily test `medvars'
	capture noisily test med_scoll med_collplus
	local rhomm_ivpw`zval' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
	estimates store estmm_ivpw`zval'
	estat firststage
	hausman estmm_ivpw`zval' estmm_ols`zval', constant
	local Hmpw`zval' = r(p)



***  Testing if father wages matter (which would indicate concerns about selection into work)

summ ln_wage_f,d
local med_ln_wage_f = r(p50)


regress ln_tau_m_g_exp_ratio  ln_wage_m_rel `Zm5'	if ln_wage_f !=.
estimates store estm_ols_5
local rssm_ols_5a=e(rss)
local nm_ols_5a=e(N)
local k2m_ols_5a=9


regress ln_tau_m_g_exp_ratio  ln_wage_m_rel `Zm5'	if ln_wage_f <= `med_ln_wage_f' & ln_wage_f !=.
estimates store estm_ols_5_lo
local rssm_ols_5_lo=e(rss)


regress ln_tau_m_g_exp_ratio  ln_wage_m_rel `Zm5'	if ln_wage_f > `med_ln_wage_f' & ln_wage_f !=.
estimates store estm_ols_5_hi
local rssm_ols_5_hi=e(rss)

*F-stat: test difference in coefficients (high/low father's wage)
local Fm_ols_5a=(`nm_ols_5a'-2*`k2m_ols_5a')/`k2m_ols_5a'*(`rssm_ols_5a'-`rssm_ols_5_lo' -`rssm_ols_5_hi')/(`rssm_ols_5_lo' +`rssm_ols_5_hi')
local pm_ols_5a=Ftail(`k2m_ols_5a',`nm_ols_5a'-2*`k2m_ols_5a',`Fm_ols_5a')
local p: display %4.3f `pm_ols_5a'
estadd scalar p_val_a= `pm_ols_5a' : estm_ols_5




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-11: OLS estimates for mother time/goods relative demand by father's wage
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab  estm_ols_5 estm_ols_5_lo estm_ols_5_hi using "$tables/Mar_S1m_OLS_fwage.tex", coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children")  stats(r2 rss N , fmt(3 3 0))  ti(Appendix Table: OLS estimates for mother time/goods relative demand by father wage (MARRIED, 1-2 kids ages 0-12, P(work) $ \geq $ `p_work_min_m' 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(15) modelwidth(13) wrap style(tex) mtitles("All" "Below Median" "Above Median")  replace addnotes("p-value for (2) and (3) = `p'")



****  Some control function selection correction estimates **** 

clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
keep if curr_married==1


disp _n(3) "HECKMAN TWO-STEP Estimates" _n(2)


heckman ln_tau_m_g_exp_ratio  ln_wage_m_rel `medvars' m_age `famvars' age i.year, select(pos_hrs_m = `medvars' m_age `famvars'  age i.year `fedvars' f_age) twostep
estimates store heck1

heckman ln_tau_m_g_exp_ratio  ln_wage_m_rel med_scoll med_collplus m_age `famvars' age i.year, select(pos_hrs_m = med_scoll med_collplus m_age `famvars'  age i.year `fedvars' f_age) twostep
estimates store heck2


heckman ln_tau_m_g_exp_ratio  ln_wage_m_rel med_scoll med_collplus m_age `famvars' age i.year, select(pos_hrs_m = med_scoll med_collplus m_age `famvars' age i.year ln_pchcare_4ca) twostep
estimates store heck3c

heckman ln_tau_m_g_exp_ratio  ln_wage_m_rel med_scoll med_collplus m_age `famvars' age i.year, select(pos_hrs_m = med_scoll med_collplus m_age `famvars' age i.year `fedvars' f_age ln_pchcare_4ca) twostep
estimates store heck4c

heckman ln_tau_m_g_exp_ratio  ln_wage_m_rel med_scoll med_collplus m_age `famvars' age i.year if prob_work_m >= `p_work_min_m' & prob_work_m !=., select(pos_hrs_m = med_scoll med_collplus m_age `famvars' age i.year `fedvars' f_age ln_pchcare_4ca) twostep
estimates store heck5c




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-9: Heckman two-step estimates for mother time/goods relative demand (two-parent households)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab  heck1 heck2 heck3c heck4c heck5c using "$tables/Mar_S1m_Heckman.tex", coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{m,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children")  stats(N N_selected, fmt(0 0))  ti(Appendix Table: Heckman two-step estimates for mother time/goods relative demand (MARRIED, 1-2 kids ages 0-12, 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(20) modelwidth(30) wrap style(tex) mtitles("father only" "father only"  "P_c only"  "Both" "Both, P(work) $ \geq $ `p_work_min_m'")  replace



************* Father's time vs. goods  **********************

clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
keep if curr_married==1
*Probability of work restriction > 0.9
keep if prob_work_f >= `p_work_min_f' & prob_work_f !=.



* OLS estimates

forvalues zval=5/7 {
	disp _n(3) "OLS Specification " `zval' _n(2)
	regress ln_tau_f_g_exp_ratio  ln_wage_f_rel  `Zf`zval''	
	predict PHIf_ols`zval'
	nlcom rho: _b[ln_wage_f_rel]/(_b[ln_wage_f_rel] -1.0)
	capture noisily test `fedvars'
	capture noisily test fed_scoll fed_collplus
	local rhof_ols`zval' = _b[ln_wage_f_rel]/(_b[ln_wage_f_rel] -1.0)
	capture noisily 
	estimates store estf_ols`zval'
}
	
	
* IV estimates: state of residence

local zval=5 
	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_f_g_exp_ratio `Zf`zval''  (ln_wage_f_rel=i.state i.year)
	predict PHIf_ivs`zval'
	nlcom rho: _b[ln_wage_f_rel]/(_b[ln_wage_f_rel] -1.0)
	capture noisily test `fedvars'
	capture noisily test fed_scoll fed_collplus
	local rhof_ivs`zval' = _b[ln_wage_f_rel]/(_b[ln_wage_f_rel] -1.0)
	estimates store estf_ivs`zval'
	estat firststage
	hausman estf_ivs`zval' estf_ols`zval', constant
	local Hf`zval' = r(p)



* IV estimates: predicted wages

local zval=5 
	disp _n(3) "IV Specification " `zval' _n(2)
	ivregress 2sls ln_tau_f_g_exp_ratio `Zf`zval''  (ln_wage_f_rel=f_pw_inst)
	predict PHIf_ivpw`zval'
	nlcom rho: _b[ln_wage_f_rel]/(_b[ln_wage_f_rel] -1.0)
	capture noisily test `fedvars'
	capture noisily test fed_scoll fed_collplus
	local rhof_ivpw`zval' = _b[ln_wage_f_rel]/(_b[ln_wage_f_rel] -1.0)
	estimates store estf_ivpw`zval'
	estat firststage
	hausman estf_ivpw`zval' estf_ols`zval', constant
	local Hfpw`zval' = r(p)


******* Tests of equality of columns 2-4, Table 3 *******
clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007

****Tests for Table 3
*Table 3 regressions 2-4
regress ln_tau_m_g_exp_ratio ln_wage_m_rel `Zm5' if (curr_married==0 & prob_work_m >= `p_work_min_m' & prob_work_m !=.)
estimates store est_t3_col2

regress ln_tau_m_g_exp_ratio ln_wage_m_rel `Zm5' if (curr_married==1 & prob_work_m >= `p_work_min_m' & prob_work_m !=.)
estimates store est_t3_col3

regress ln_tau_f_g_exp_ratio ln_wage_f_rel `Zf5' if (curr_married==1 & prob_work_f >= `p_work_min_f' & prob_work_f !=.)
estimates store est_t3_col4

suest est_t3_col2 est_t3_col3 est_t3_col4

*Test for equality of log wage coefficients across columns 2-4
test [est_t3_col2_mean]ln_wage_m_rel = [est_t3_col3_mean]ln_wage_m_rel = [est_t3_col4_mean]ln_wage_f_rel

*Joint test for equality of remaining coefficients across columns 2-4
test ([est_t3_col2_mean]age = [est_t3_col3_mean]age = [est_t3_col4_mean]age) ([est_t3_col2_mean]med_scoll = [est_t3_col3_mean]med_scoll = [est_t3_col4_mean]fed_scoll) ([est_t3_col2_mean]med_collplus = [est_t3_col3_mean]med_collplus = [est_t3_col4_mean]fed_collplus) ([est_t3_col2_mean]m_age = [est_t3_col3_mean]m_age = [est_t3_col4_mean]f_age) ([est_t3_col2_mean]m_white = [est_t3_col3_mean]m_white = [est_t3_col4_mean]m_white) ([est_t3_col2_mean]num_0_5 = [est_t3_col3_mean]num_0_5 = [est_t3_col4_mean]num_0_5) ([est_t3_col2_mean]num_child = [est_t3_col3_mean]num_child = [est_t3_col4_mean]num_child) ([est_t3_col2_lnvar]_cons = [est_t3_col3_lnvar]_cons = [est_t3_col4_lnvar]_cons)

*Joint test for equality of all coefficients across columns 2-4
test ([est_t3_col2_mean]ln_wage_m_rel = [est_t3_col3_mean]ln_wage_m_rel = [est_t3_col4_mean]ln_wage_f_rel) ([est_t3_col2_mean]age = [est_t3_col3_mean]age = [est_t3_col4_mean]age) ([est_t3_col2_mean]med_scoll = [est_t3_col3_mean]med_scoll = [est_t3_col4_mean]fed_scoll) ([est_t3_col2_mean]med_collplus = [est_t3_col3_mean]med_collplus = [est_t3_col4_mean]fed_collplus) ([est_t3_col2_mean]m_age = [est_t3_col3_mean]m_age = [est_t3_col4_mean]f_age) ([est_t3_col2_mean]m_white = [est_t3_col3_mean]m_white = [est_t3_col4_mean]m_white) ([est_t3_col2_mean]num_0_5 = [est_t3_col3_mean]num_0_5 = [est_t3_col4_mean]num_0_5) ([est_t3_col2_mean]num_child = [est_t3_col3_mean]num_child = [est_t3_col4_mean]num_child) ([est_t3_col2_lnvar]_cons = [est_t3_col3_lnvar]_cons = [est_t3_col4_lnvar]_cons)

*Joint test for equality of all coefficients but intercept and coefficient on log relative wages across columns 2-4
test ([est_t3_col2_mean]age = [est_t3_col3_mean]age = [est_t3_col4_mean]age) ([est_t3_col2_mean]med_scoll = [est_t3_col3_mean]med_scoll = [est_t3_col4_mean]fed_scoll) ([est_t3_col2_mean]med_collplus = [est_t3_col3_mean]med_collplus = [est_t3_col4_mean]fed_collplus) ([est_t3_col2_mean]m_age = [est_t3_col3_mean]m_age = [est_t3_col4_mean]f_age) ([est_t3_col2_mean]m_white = [est_t3_col3_mean]m_white = [est_t3_col4_mean]m_white) ([est_t3_col2_mean]num_0_5 = [est_t3_col3_mean]num_0_5 = [est_t3_col4_mean]num_0_5) ([est_t3_col2_mean]num_child = [est_t3_col3_mean]num_child = [est_t3_col4_mean]num_child)

*Test for equality of intercepts across columns 2-4
test ([est_t3_col2_lnvar]_cons = [est_t3_col3_lnvar]_cons = [est_t3_col4_lnvar]_cons)

*Joint test for equality of all coefficients but intercept across columns 2-4
test ([est_t3_col2_mean]ln_wage_m_rel = [est_t3_col3_mean]ln_wage_m_rel = [est_t3_col4_mean]ln_wage_f_rel) ([est_t3_col2_mean]age = [est_t3_col3_mean]age = [est_t3_col4_mean]age) ([est_t3_col2_mean]med_scoll = [est_t3_col3_mean]med_scoll = [est_t3_col4_mean]fed_scoll) ([est_t3_col2_mean]med_collplus = [est_t3_col3_mean]med_collplus = [est_t3_col4_mean]fed_collplus) ([est_t3_col2_mean]m_age = [est_t3_col3_mean]m_age = [est_t3_col4_mean]f_age) ([est_t3_col2_mean]m_white = [est_t3_col3_mean]m_white = [est_t3_col4_mean]m_white) ([est_t3_col2_mean]num_0_5 = [est_t3_col3_mean]num_0_5 = [est_t3_col4_mean]num_0_5) ([est_t3_col2_mean]num_child = [est_t3_col3_mean]num_child = [est_t3_col4_mean]num_child)

*Joint test for equality of all coefficients but intercept across columns 2 and 3
test ([est_t3_col2_mean]ln_wage_m_rel = [est_t3_col3_mean]ln_wage_m_rel) ([est_t3_col2_mean]age = [est_t3_col3_mean]age) ([est_t3_col2_mean]med_scoll = [est_t3_col3_mean]med_scoll) ([est_t3_col2_mean]med_collplus = [est_t3_col3_mean]med_collplus) ([est_t3_col2_mean]m_age = [est_t3_col3_mean]m_age) ([est_t3_col2_mean]m_white = [est_t3_col3_mean]m_white) ([est_t3_col2_mean]num_0_5 = [est_t3_col3_mean]num_0_5) ([est_t3_col2_mean]num_child = [est_t3_col3_mean]num_child)



******* Super-summary Tables for all Parent types (spec 5 and 7)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Table 3: OLS estimates for parental time vs. goods relative demand, by parent type
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab estm_ols5 estms_ols5 estmm_ols5 estf_ols5 using "$tables/Parents_5a.tex", rename (ln_wage_f_rel ln_wage_m_rel) coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{j,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children"  fed_hs "Father HS grad"  fed_scoll "Father some coll."  fed_collplus "Father coll+" f_age "Father's age") stats(r2 N, fmt(3 0))  ti(Table: OLS estimates for parental time vs.\ goods relative demand (1-2 kids ages 0-12, P(work) $\geq$ `p_work_min_m' or `p_work_min_f', 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(20) modelwidth(12) wrap style(tex) mtitles("All Mother" "Single Mother" "Married Mother" "Married Father")   replace



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-7: 2SLS estimates for parental time vs. goods relative demand
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab estm_ivpw5 estms_ivpw5 estmm_ivpw5 estf_ivpw5 using "$tables/Parents_5c.tex", rename (ln_wage_f_rel ln_wage_m_rel)  coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{j,i})$"  curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children"  fed_hs "Father HS grad"  fed_scoll "Father some coll."  fed_collplus "Father coll+" f_age "Father's age") stats(r2 N, fmt(3 0))  ti(Appendix Table: IV (predicted wage) estimates for parental time vs.\ goods relative demand (1-2 kids ages 0-12, P(work) $\geq$ `p_work_min_m' or `p_work_min_f', 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(20) modelwidth(12) wrap style(tex) mtitles("All Mother" "Single Mother" "Married Mother" "Married Father")    replace

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-8: OLS estimates for parental time vs. goods relative demand including parental 
*** log wage fixed effects, by parent type
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab estm_ols7 estms_ols7 estmm_ols7 estf_ols7 using "$tables/Parents_7a.tex", rename (ln_wage_f_rel ln_wage_m_rel) coeflab(ln_wage_m_rel "$\ln(\tilde{W}_{j,i})$" curr_married "Married"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"  m_age "Mother's age" m_white "Mother white"  num_0_5 "Num children age 0-5" num_child "Num of children"  fed_hs "Father HS grad"  fed_scoll "Father some coll."  fed_collplus "Father coll+" f_age "Father's age" ln_wageFE_m "Mother's log wage FE" ln_wageFE_f "Father's log wage FE")  stats(r2 N, fmt(3 0))  ti(Appendix Table: OLS estimates for parental time vs.\ goods relative demand (1-2 kids ages 0-12, P(work) $\geq$ `p_work_min_m' or `p_work_min_f', 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(20) modelwidth(12) wrap style(tex) mtitles("All Mother" "Single Mother" "Married Mother" "Married Father")  replace


}






if $est_chcare_goods==1 {

clear all


****************************************************************************************************
******************** F. ESTIMATION: CHILD CARE VS. HOUSEHOLD GOODS  ********************************
****************************************************************************************************


*********** SINGLE MOTHERS (2002, 2007) ************

clear
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
keep if curr_married==0

* keep if prob_work_m >= `p_work_min_m' & prob_work_m !=. //restrict to high work probability


* first stage specification for time vs. goods (use only those with high probability of work, but generate predicted probability for all)

local Zmspec = "5"

regress ln_tau_m_g_exp_ratio  ln_wage_m_rel  `Zm`Zmspec''	if prob_work_m >= `p_work_min_m' & prob_work_m !=.
predict lnPHIms_ols`Zmspec', xb      // predicted time relative to good expenditures, Phi_m, for single mothers

nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)
local rhom_ols`Zmspec' = _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)

summ lnPHIms_ols`Zmspec' ln_tau_m_g_exp_ratio

regress ln_tau_m_g_exp_ratio  ln_wage_m_rel  `Zm`Zmspec''	 if (ln_hhinvest !=. & ln_invratio_imp !=.)
nlcom rho: _b[ln_wage_m_rel]/(_b[ln_wage_m_rel] -1.0)


* Generate nonlinear terms for below

gen logtermPHI = ln(1.0 + exp(lnPHIms_ols`Zmspec'))
	
gen temp    = 1.0 + exp(ln_tau_m_g_exp_ratio)
gen logterm = ln(temp)
gen term2   = exp(ln_tau_m_g_exp_ratio)/(2.0*temp*temp)	

summ logtermPHI temp logterm term2


* OLS estimation of child care vs. goods equation only

foreach pvar in 4ca{

    disp  _n(3) "SINGLE MOTHERS, CHILD CARE VS. GOODS" 
    disp  _n(1) "Price measure: `pvar'" 
	disp        "first stage specification Zm`Zmspec'" _n(2)
	
* OLS estimates

	forvalues zval=1/7 {
		regress ln_invratio_imp  ln_pratio_`pvar' `Zm`zval''
		nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		local gam_S_ols`zval' = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		capture noisily test `medvars'
	    capture noisily test med_scoll med_collplus
		estimates store estS_ols`zval'
	}
	
	
	* get a de-meaned and re-scaled value of ln_hhinvest for relevant sample for regressor in Y vs. g relative demand equation -- (ln(g)-E[ln(g)])/Var(ln(g)) 
		
	gen nonmiss_Yvg = (ln_invratio_imp !=. & ln_tau_m_g_exp_ratio !=. & ln_pratio_`pvar' !=. & ln_hhinv !=.)  // note that logterm and term2 variables are functions of ln_tau_m_g_exp_ratio
	foreach zvar in `Zm5'{
		replace nonmiss_Yvg=0 if `zvar'==.     // setting indicator to zero if variable is missing
	}

	summ ln_hhinvest if (nonmiss_Yvg==1)	          
	gen d_ln_hhinv = (ln_hhinvest - r(mean))/r(Var)   
	summ ln_hhinvest d_ln_hhinv	
	
	
	disp _n(3) "OLS with nonlinear terms"	
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zm5' logterm                   // no input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	local gam_S_log = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store estS_log
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zm5' logterm term2 d_ln_hhinv  // includes terms for input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	local gam_S_ME = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store estS_ME		
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zm5' logtermPHI                // includes predicted relative time/goods expenditure
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logtermPHI])
	capture noisily test med_scoll med_collplus
	local gam_S_PHI = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store estS_PHI
	

	drop d_ln_hhinv nonmiss_Yvg

} // end loop over pvar




*********** Two-Parent Households (2002, 2007) ***********

clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007
keep if curr_married==1

* keep if prob_work_m >= `p_work_min_m' & prob_work_m !=. &  prob_work_f >= `p_work_min_f' & prob_work_f !=.  // comment/uncomment depending on if want to restrict sample to this with high probability of work



* First-stage PHI functions

local Zspec = "5"
	
regress ln_tau_m_g_exp_ratio  ln_wage_m_rel  `Zm`Zspec''	if prob_work_m >= `p_work_min_m' & prob_work_m !=.
predict lnPHImm_ols`Zspec', xb      // predicted time relative to good expenditures, Phi_m, for married mothers

regress ln_tau_f_g_exp_ratio  ln_wage_f_rel  `Zf`Zspec''	if prob_work_f >= `p_work_min_f' & prob_work_f !=.
predict lnPHIf_ols`Zspec', xb       // predicted time relative to good expenditures, Phi_f, for fathers

summ lnPHImm_ols`Zspec' lnPHIf_ols`Zspec' ln_tau_m_g_exp_ratio ln_tau_m_g_exp_ratio



* Generate nonlinear terms for below

gen logtermPHI = ln(1.0 + exp(lnPHImm_ols`Zspec') + exp(lnPHIf_ols`Zspec'))
	
gen Rf = exp(ln_tau_f_g_exp_ratio)
gen Rm = exp(ln_tau_m_g_exp_ratio)
		
gen temp    = 1.0 + Rm + Rf
gen logterm = ln(temp)
gen term_f   = Rf*(1.0 + Rm)/(2.0*temp*temp)	
gen term_m   = Rm*(1.0 + Rf)/(2.0*temp*temp)
gen term_g   = (Rf + Rm)/(2.0*temp*temp) 
		
summ Rf Rm logterm term_f term_m term_g 
corr logterm term_f term_m term_g 

 
foreach pvar in 4ca{

    disp  _n(3) "MARRIED COUPLES, CHILD CARE VS. GOODS" 
    disp  _n(1) "Price measure: `pvar'" _n(1)		
	
* OLS estimates

	local zval= 5
		regress ln_invratio_imp  ln_pratio_`pvar' `Z`zval''
		nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		local gam_M_ols`zval' = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		capture noisily test med_scoll med_collplus
		capture noisily test fed_scoll fed_collplus
		estimates store est_M_ols`zval'
		
	
	* get a de-meaned and re-scaled value of ln_hhinvest for relevant sample for regressor in Y vs. g relative demand equation -- (ln(g)-E[ln(g)])/Var(ln(g)) 
		
	gen nonmiss_Yvg = (ln_invratio_imp !=. & ln_tau_m_g_exp_ratio !=. & ln_tau_f_g_exp_ratio !=. & ln_pratio_`pvar' !=. & ln_hhinv !=.)  // note that logterm and other nonlinear terms are functions of ln_tau_m_g_exp_ratio & ln_tau_m_g_exp_ratio
	foreach zvar in `Z5'{
		replace nonmiss_Yvg=0 if `zvar'==.     // setting indicator to zero if variable is missing
	}
	
	summ ln_hhinvest if (nonmiss_Yvg==1)	         
	gen d_ln_hhinv = (ln_hhinvest - r(mean))/r(Var)   
	summ ln_hhinvest d_ln_hhinv	
	
	
	disp _n(3) "OLS with nonlinear terms"	
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Z5' logterm                                // no input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_scoll fed_collplus
	local gam_M_log = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_M_log
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Z5' logterm term_f term_m term_g d_ln_hhinv  // includes terms for input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_scoll fed_collplus
	local gam_M_ME = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_M_ME		
		
	regress ln_invratio_imp  ln_pratio_`pvar'  `Z5' logtermPHI                            // includes predicted relative time/goods expenditure
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logtermPHI])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_scoll fed_collplus
	local gam_M_PHI = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_M_PHI
	
	
	drop d_ln_hhinv nonmiss_Yvg
	
} // end loop over pvar




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-15: OLS estimates for child care/goods relative demand
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

esttab estS_ols5 estS_log estS_PHI estS_ME est_M_ols5 est_M_log est_M_PHI est_M_ME  using "$tables/Sing_Mar_YPvpg_OLS.tex", coeflab(ln_pratio_`pvar' "$\ln(\tilde{P}_c)$"  age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"   fed_hs "Father HS grad"  fed_scoll "Father some coll."  fed_collplus "Father coll+" f_age "Father's age" m_age "Mother's age" m_white "Mother white" m_pc97 "Mother's cogn. score" num_child "Num of children" num_0_5 "Num children age 0-5" logterm "$\ln(1+R_m+R_f)$" logtermPHI "$\ln(1+e^{\Phi_m}+e^{\Phi_f})$" d_ln_hhinv "$-\sigma^2_g$")  stats(r2 N, fmt(3 0))  ti(OLS estimates for child care/goods relative demand (4ca, 1-2 kids ages 0-12, 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(40) modelwidth(10) wrap style(tex) mtitles("Single" "Single" "Single" "Single" "Married" "Married" "Married" "Married")  replace 



***** ALL Households (2002, 2007) *****


clear 
use "$temp/allfam_tmp.dta"

keep if year==2002 | year==2007

* keep if prob_work_m >= `p_work_min_m' & prob_work_m !=. &  prob_work_f >= `p_work_min_f' & prob_work_f !=.  // comment/uncomment depending on if want to restrict sample to this with high probability of work


* First-stage PHI functions

local Zspec = "5"


regress ln_tau_m_g_exp_ratio  ln_wage_m_rel curr_married  `Zm`Zspec''	if prob_work_m >= `p_work_min_m' & prob_work_m !=.
predict lnPHIm_ols`Zspec', xb      // predicted time relative to good expenditures, Phi_m, for all mothers

regress ln_tau_f_g_exp_ratio  ln_wage_f_rel  `Zf`Zspec''	if prob_work_f >= `p_work_min_f' & prob_work_f !=.
predict lnPHIf_ols`Zspec', xb       // predicted time relative to good expenditures, Phi_f, for fathers

summ lnPHIm_ols`Zspec' lnPHIf_ols`Zspec' ln_tau_m_g_exp_ratio ln_tau_m_g_exp_ratio



* Generate nonlinear terms for below

gen logtermPHI = ln(1.0 + exp(lnPHIm_ols`Zspec') + exp(lnPHIf_ols`Zspec'))
replace logtermPHI = ln(1.0 + exp(lnPHIm_ols`Zspec')) if curr_married==0
	
gen Rf = exp(ln_tau_f_g_exp_ratio)
gen Rm = exp(ln_tau_m_g_exp_ratio)
		
gen temp    = 1.0 + Rm + Rf
replace temp = 1.0 + Rm   if curr_married==0

gen logterm = ln(temp)

gen term_f   = Rf*(1.0 + Rm)/(2.0*temp*temp)
gen term_m   = Rm*(1.0 + Rf)/(2.0*temp*temp)
gen term_g   = (Rf + Rm)/(2.0*temp*temp) 
		
replace term_f = 0 if curr_married==0
replace term_m = Rm/(2.0*temp*temp) if curr_married==0
replace term_g = 0 if curr_married==0

summ curr_married logtermPHI Rf Rm logterm term_f term_m term_g 
corr logterm term_f term_m term_g 


 
foreach pvar in 4ca {

    disp  _n(3) "ALL HH, CHILD CARE VS. GOODS" 
    disp  _n(1) "Price measure: `pvar'" _n(1)		
	
* OLS estimates


local zval= 5 
		regress ln_invratio_imp  ln_pratio_`pvar' `Zall`zval''
		nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		local gam_ols`zval' = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		capture noisily test med_scoll med_collplus
		capture noisily test fed_all_scoll fed_all_collplus
		estimates store est_ols`zval'
		
		local rss_ols`zval'=e(rss)
		local n_ols`zval'=e(N)


		regress ln_invratio_imp  ln_pratio_`pvar' `Zall`zval'' SR
		nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		local gam_ols_SR_`zval' = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
		capture noisily test med_scoll med_collplus
		capture noisily test fed_all_scoll fed_all_collplus
		estimates store est_ols_SR_`zval'

	
	* get a de-meaned and re-scaled value of ln_hhinvest for relevant sample for regressor in Y vs. g relative demand equation -- (ln(g)-E[ln(g)])/Var(ln(g)) 
		
	gen nonmiss_Yvg = (ln_invratio_imp !=. & temp !=. & ln_pratio_`pvar' !=. & ln_hhinv !=.)  // note that nonlinear terms are missing if temp is missing
	foreach zvar in `Zall5'{
		replace nonmiss_Yvg=0 if `zvar'==.     // setting indicator to zero if variable is missing
	}
	
	summ ln_hhinvest if (nonmiss_Yvg==1)	          // NEW  
	gen d_ln_hhinv = (ln_hhinvest - r(mean))/r(Var)   // NEW  
	summ ln_hhinvest d_ln_hhinv	
	
	
	disp _n(3) "OLS with nonlinear terms -- without staff ratio"	
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' logterm                                // no input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	local gam_log = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_log
	local rss_log=e(rss)
	local n_log=e(N)
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' logterm term_f term_m term_g d_ln_hhinv  // includes terms for input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	local gam_ME = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_ME		
		
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' logtermPHI                            // includes predicted relative time/goods expenditure
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logtermPHI])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	local gam_PHI = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_PHI
	local rss_PHI=e(rss)
	local n_PHI=e(N)
	
	
	disp _n(3) "OLS with nonlinear terms -- with staff ratio"	
	
	replace nonmiss_Yvg = 0 if SR==.   // set indicator to zero if staff ratio measure is missing
	summ ln_hhinvest if (nonmiss_Yvg==1)	          
	replace d_ln_hhinv = (ln_hhinvest - r(mean))/r(Var)   
	summ ln_hhinvest d_ln_hhinv	
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' SR logterm                                // no input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	local gam_SR_log = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_SR_log
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' SR logterm term_f term_m term_g d_ln_hhinv  // includes terms for input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logterm])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	local gam_SR_ME = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_SR_ME		
		
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' SR logtermPHI                            // includes predicted relative time/goods expenditure
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	nlcom rho: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0 + _b[logtermPHI])
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	local gam_SR_PHI = _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	estimates store est_SR_PHI

	
	

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
***  Table 4: OLS estimates for child care/goods relative demand, all families
**Note: Columns 1-4 correspond to Table 4, Column 5 corresponds to Table E-1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	esttab est_ols5 est_ols_SR_5  est_log est_PHI est_ME   using "$tables/All_YPvpg_`pvar'_OLS.tex", coeflab(ln_pratio_`pvar' "$\ln(\tilde{P}_{c,i})$" curr_married "Married" age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"   fed_all_hs "Marr x Father HS grad"  fed_all_scoll "Marr x Father some coll."  fed_all_collplus "Marr x Father coll+" f_all_age "Marr x Father's age" m_age "Mother's age" m_white "Mother white" m_pc97 "Mother's cogn. score" num_child "Num of children" num_0_5 "Num children age 0-5" SR "staff ratio" logterm "$\ln(1+R_m + Marr\cdot R_f)$" logtermPHI "$\ln(1+e^{\Phi_m}+Marr\cdot e^{\Phi_f})$" d_ln_hhinv "$-\sigma^2_g$")  stats(r2 rss N, fmt(3 3 0))  ti(OLS estimates for child care/goods relative demand (ALL, `pvar', 1-2 kids ages 0-12, 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(43) modelwidth(10) wrap style(tex) mlabels(,none)  replace 
	


	**** Heckman selection corrected models for positive childcare expenditures
	
	
	disp _n(3) "HECKMAN TWO-STEP Estimates" _n(2)
	

	heckman ln_invratio_imp  ln_pratio_`pvar' `Zall5', select(`pccare'  = ln_pratio_`pvar' `Zall5' i.year  ind_same_state live_grand old_child old_child_2plus) twostep
	estimates store heck_old
	
	heckman ln_invratio_imp  ln_pratio_`pvar' `Zall5', select(`pccare'  = ln_pratio_`pvar' `Zall5' i.year  ind_same_state older_relative_hh old_child old_child_2plus) twostep
	estimates store heck_base
	
	
	heckman ln_invratio_imp  ln_pratio_`pvar' `Zall5', select(`pccare'  = ln_pratio_`pvar' `Zall5' i.year ind_same_state old_child old_child_2plus) twostep
	estimates store heck_base2
	
	
	heckman ln_invratio_imp  ln_pratio_`pvar' `Zall5' logtermPHI, select(`pccare'  = ln_pratio_`pvar' `Zall5' i.year  ind_same_state old_child old_child_2plus) twostep
	estimates store heck_PHI
	
	heckman ln_invratio_imp  ln_pratio_`pvar' `Zall5' logtermPHI, select(`pccare'  = ln_pratio_`pvar' `Zall5' i.year logtermPHI ind_same_state old_child old_child_2plus) twostep
	estimates store heck_PHI2
	

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
***  Appendix  Table G-14: Heckman two-step estimates for childcare/goods relative demand
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	esttab  heck_base heck_base2 heck_PHI2 using "$tables/All_YPvpg_`pvar'_OLS_Heckman.tex", coeflab(ln_pratio_`pvar' "$\ln(\tilde{P}_{c,i})$" curr_married "Married" age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"   fed_all_hs "Marr x Father HS grad"  fed_all_scoll "Marr x Father some coll."  fed_all_collplus "Marr x Father coll+" f_all_age "Marr x Father's age" m_age "Mother's age" m_white "Mother white" num_child "Num of children" num_0_5 "Num children age 0-5" logtermPHI "$\ln(1+e^{\Phi_m}+Marr\cdot e^{\Phi_f})$" ind_same_state "HH Head same state" live_grand "Live w/grandparents" older_relative_hh "live w/older relative" old_child "Any children ages 13+" old_child_2plus "2+ children ages 13+") stats(N_selected N, fmt(0 0))  ti(Appendix Table: Heckman two-step estimates for childcare/goods relative demand (ALL, `pvar', 1-2 kids ages 0-12, 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(44) modelwidth(15) wrap style(tex)  mlabels(,none)  replace
	
	
	
	**** Estimate separate models by child age
	
	regress ln_invratio_imp  ln_pratio_`pvar' `Zall5' if age >=5 & age <=8
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	estimates store est_ols5_5_8
	local rss_ols5_5_8=e(rss)
	
	regress ln_invratio_imp  ln_pratio_`pvar' `Zall5' if age >=9 & age <=12
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	estimates store est_ols5_9_12	
	local rss_ols5_9_12=e(rss)
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' logterm   if age >=5 & age <=8    // no input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	estimates store est_log_5_8	
	local rss_log_5_8=e(rss)
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' logterm   if age >=9 & age <=12    // no input measurement error case
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)	
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	estimates store est_log_9_12	
	local rss_log_9_12=e(rss)
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' logtermPHI if age >=5 & age <=8    // includes predicted relative time/goods expenditure
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	estimates store est_PHI_5_8
	local rss_PHI_5_8=e(rss)
	
	regress ln_invratio_imp  ln_pratio_`pvar'  `Zall5' logtermPHI if age >=9 & age <=12    // includes predicted relative time/goods expenditure
	nlcom gamma: _b[ln_pratio_`pvar']/(_b[ln_pratio_`pvar'] -1.0)
	capture noisily test med_scoll med_collplus
	capture noisily test fed_all_scoll fed_all_collplus
	estimates store est_PHI_9_12
	local rss_PHI_9_12=e(rss)
	
	
	
	**F-stat:  compare coefficients for all children vs children ages 5-8 and 9-12

local k2_ols5=13
local k2_log=14
local k2_PHI=14

local k_PHI_age=17
local k2_PHI_age=3


foreach var in "ols5" "log" "PHI" {

local F_`var'=(`n_`var''-2*`k2_`var'')/`k2_`var''*(`rss_`var''-(`rss_`var'_5_8'+`rss_`var'_9_12'))/(`rss_`var'_5_8'+`rss_`var'_9_12')
local pf_`var'=Ftail(`k2_`var'',`n_`var''-2*`k2_`var'',`F_`var'')
local p_`var': display %4.3f `pf_`var''
estadd scalar p_val = `pf_`var'' : est_`var'

}

	
	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*** Appendix Table G-16: OLS estimates for child care/goods relative demand by child age
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	esttab est_ols5_5_8 est_ols5_9_12 est_log_5_8 est_log_9_12 est_PHI_5_8 est_PHI_9_12  using "$tables/All_YPvpg_`pvar'_OLS_age.tex", coeflab(ln_pratio_`pvar' "$\ln(\tilde{P}_{c,i})$" curr_married "Married" age "Child's age" med_hs "Mother HS grad"  med_scoll "Mother some coll."  med_collplus "Mother coll+"   fed_all_hs "Marr x Father HS grad"  fed_all_scoll "Marr x Father some coll."  fed_all_collplus "Marr x Father coll+" f_all_age "Marr x Father's age" m_age "Mother's age" m_white "Mother white" m_pc97 "Mother's cogn. score" num_child "Num of children" num_0_5 "Num children age 0-5" logterm "$\ln(1+R_m +Marr\cdot R_f)$" logtermPHI "$\ln(1+e^{\Phi_m}+Marr\cdot e^{\Phi_f})$")  stats(r2 rss N, fmt(3 3 0))  ti(Appendix Table: OLS estimates for child care/goods relative demand by child age (ALL, `pvar', 1-2 kids ages 0-12, 2002 and 2007)) cells(b(star fmt(3)) se(par fmt(3)))  varwidth(55) modelwidth(10) wrap style(tex) mtitles("Ages 5-8" "Ages 9-12" "Ages 5-8" "Ages 9-12" "Ages 5-8" "Ages 9-12") addnotes("p-value for (1) and (2) =  `p_ols5', p-value for (3) and (4) =  `p_log', p-value for (5) and (6) = `p_PHI'")  replace 

	drop d_ln_hhinv nonmiss_Yvg 
	
} // end loop over pvar


} // end of $est_chcare_goods=1 case



log close mainlog




